﻿using ExDUIR.NET.Declaration;
using ExDUIR.NET.Handle;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ExDUIR.NET.Path
{
    public class ExPath
    {
        private readonly ExPathHandle _handle;
        public int Handle => _handle.Handle;
        public bool IsValid => _handle.IsInvalid;
        internal ExPath(ExPathHandle handle)
        {
            _handle = handle;
        }

        internal ExPath()
        {
            int hPath;
            ExAPI._path_create(1, out hPath);
            _handle = new ExPathHandle(hPath);
        }

        public bool AddArc(float x1, float y1, float x2, float y2, float radiusX, float radiusY, bool fClockwise)
        {
            return ExAPI._path_addarc(_handle.Handle, x1, y1, x2, y2, radiusX, radiusY, fClockwise);
        }

        public bool AddArc2(float x, float y, float width, float height, float startAngle, float sweepAngle)
        {
            return ExAPI._path_addarc2(_handle.Handle, x, y, width, height, startAngle, sweepAngle);
        }

        public bool AddArc3(float x, float y, float radiusX, float radiusY, float startAngle, float sweepAngle, bool fClockwise, bool barcSize)
        {
            return ExAPI._path_addarc3(_handle.Handle, x, y, radiusX, radiusY, startAngle, sweepAngle, fClockwise, barcSize);
        }

        public bool AddEllipse(float left, float top, float right, float bottom)
        {
            return ExAPI._path_addellipse(_handle.Handle, left, top, right, bottom);
        }

        public bool AddLine(float x1, float y1, float x2, float y2)
        {
            return ExAPI._path_addline(_handle.Handle, x1, y1, x2, y2);
        }

        public bool AddQuadraticBezier(float x1, float y1, float x2, float y2)
        {
            return ExAPI._path_addquadraticbezier(_handle.Handle, x1, y1, x2, y2);
        }

        public bool AddRect(float left, float top, float right, float bottom)
        {
            return ExAPI._path_addrect(_handle.Handle, left, top, right, bottom);
        }

        public bool AddRoundedRect(float left, float top, float right, float bottom, float radiusTopLeft, float radiusTopRight, float radiusBottomLeft, float radiusBottomRight)
        {
            return ExAPI._path_addroundedrect(_handle.Handle, left, top, right, bottom, radiusTopLeft, radiusTopRight, radiusBottomLeft, radiusBottomRight);
        }

        public bool BeginFigure()
        {
            return ExAPI._path_beginfigure(_handle.Handle);
        }

        public bool BeginFigue(float x, float y)
        {
            return ExAPI._path_beginfigure2(_handle.Handle, x, y);
        }

        public bool BeginFigue(float x, float y, int figureBegin)
        {
            return ExAPI._path_beginfigure3(_handle.Handle, x, y, figureBegin);
        }

        public bool Close()
        {
            return ExAPI._path_close(_handle.Handle);
        }

        public bool EndFigure(bool fCloseFigure)
        {
            return ExAPI._path_endfigure(_handle.Handle, fCloseFigure);
        }

        public ExRectF Bounds
        {
            get
            {
                ExRectF lpBounds = new ExRectF();
                ExAPI._path_getbounds(_handle.Handle, ref lpBounds);
                return lpBounds;
            }
        }

        public bool HitTest(float x, float y)
        {
            return ExAPI._path_hittest(_handle.Handle, x, y);
        }

        public bool Open()
        {
            return ExAPI._path_open(_handle.Handle);
        }

        public bool Reset()
        {
            return ExAPI._path_reset(_handle.Handle);
        }

        public bool AddBezier(float x1, float y1, float x2, float y2, float x3, float y3)
        {
            return ExAPI._path_addbezier(_handle.Handle, x1, y1, x2, y2, x3, y3);
        }

        public void Dispose() => _handle.Dispose();
    }
}
